package cn.dansj.common.utils.redis;

import cn.dansj.common.utils.redis.serializer.StringSerializer;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

public class StringRedisTemplate extends RedisTemplate<String, String> {
    public StringRedisTemplate() {
        setKeySerializer(StringSerializer.getInstance());
        setValueSerializer(StringSerializer.getInstance());
        setHashKeySerializer(StringSerializer.getInstance());
        setHashValueSerializer(StringSerializer.getInstance());
        setStringSerializer(StringSerializer.getInstance());
        setDefaultSerializer(StringSerializer.getInstance());
    }

    public StringRedisTemplate(RedisConnectionFactory connectionFactory) {
        this();
        setConnectionFactory(connectionFactory);
        afterPropertiesSet();
    }

    protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
        return new DefaultStringRedisConnection(connection);
    }
}
